package com.secret.chain.secretchain.service.impl;

import com.secret.chain.secretchain.domain.entity.Group;
import com.secret.chain.secretchain.mapper.GroupMapper;
import com.secret.chain.secretchain.result.Result;
import com.secret.chain.secretchain.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class GroupServiceImpl implements GroupService {
    @Autowired
    private GroupMapper groupMapper;

    @Override
    public Result queryByCreatorId(Integer creatorId) {
        Group group = groupMapper.queryByCreatorId(creatorId);
        return Result.success(group);
    }

    @Override
    public Result save(Group group) {
        LocalDateTime now =LocalDateTime.now();
        group.setCreatTime(now);
        group.setStatus(1);
        groupMapper.insert(group);
        group.setRole(1);
        group.setStatus(1);
        groupMapper.insert1(group);
        return Result.success();
    }
    @Override
    public Result deleted(Integer id){
        groupMapper.deleteById(id);
        return Result.success();
    }

    @Override
    public Result put(Group group) {
        LocalDateTime now =LocalDateTime.now();
        group.setCreatTime(now);
        groupMapper.put(group);
        return Result.success();
    }

    @Override
    public Result queryByKeyword(String keyword) {
        Group group = groupMapper.queryByKeyword(keyword);
        return Result.success(group);
    }

    @Override
    public Result queryById(Integer id) {
        Group group = groupMapper.queryById(id);
        return Result.success(group);
    }
}
